#ifndef FUNCTION
#define FUNCTION

class Function {
public:
    // Pure virtual function, must be implemented in derived classes.
    virtual double operator() (double x) const = 0;

    // Default derivative function, approximating the derivative using the central difference method.
    virtual double derivative(double x, double h = 1e-6) const {
        return ( (*this)(x + h) - (*this)(x - h) ) / (2 * h); 
    }
};

#endif